package yuan.common;

import com.alibaba.fastjson.JSONObject;
import io.micrometer.core.instrument.DistributionSummary;
import io.micrometer.core.instrument.Metrics;

import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Random;

public class MySummary {
    public static String testSummary(){

        DistributionSummary summary = DistributionSummary.builder("a_test_summary")
                .tag("summary", "summarySample")
                .publishPercentiles(.1, .2, .3, .4, .5, .6, .7, .8, .9, 1)
                .publishPercentileHistogram()
//                .publishPercentiles()
//                .publishPercentileHistogram()
                .percentilePrecision(3)
                .description("summary sample test")
                .register(Metrics.globalRegistry);

        Random r = new Random();
        Double record = r.nextInt(1000)*1.0/1000;
        summary.record(record);

        System.out.println(summary.count());
        System.out.println(summary.measure());
        System.out.println(summary.max());
        System.out.println(summary.mean());
        System.out.println(summary.totalAmount());

//        PrintStream out = null;
//        try {
//            out = new PrintStream("/Users/aron/test/1.txt");
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
//        double scale = 1;
//        summary.takeSnapshot().outputSummary(out, scale);
        return record.toString();
    }

}
